package com.jetinno.bean;

import android.text.TextUtils;

import org.json.JSONObject;

/**
 * Description : 机器响应信息类
 * Author :mhwang
 * Date : 2017/9/1
 * Version : V1.0
 */
public class MachineRespond {
    private String mHexResult = "";//底层返回数据
    private String mJsonResult = "";//基于返回数据,在c++层面解析的数据
    private String mParserResult = "";//基于返回数据,解析的文案数据
    private String mSendCmd = "";//向底层发送数据
    private Object tag1 = null;//扩展标记
    private Object tag2 = null;//扩展标记
    private Object tag3 = null;//扩展标记

    public MachineRespond() {
    }

    public Object getTag1() {
        return tag1;
    }

    public void setTag1(Object tag1) {
        this.tag1 = tag1;
    }

    public Object getTag2() {
        return tag2;
    }

    public void setTag2(Object tag2) {
        this.tag2 = tag2;
    }

    public Object getTag3() {
        return tag3;
    }

    public void setTag3(Object tag3) {
        this.tag3 = tag3;
    }

    public String getHexResult() {
        return mHexResult;
    }

    public void setHexResult(String hexResult) {
        mHexResult = hexResult;
    }

    public String getJsonResult() {
        return mJsonResult;
    }

    public void setJsonResult(String jsonResult) {
        mJsonResult = jsonResult;
    }

    public String getParserResult() {
        return mParserResult;
    }

    public void setParserResult(String parserResult) {
        mParserResult = parserResult;
    }

    public String getSendCmd() {
        return mSendCmd;
    }

    public void setSendCmd(String sendCmd) {
        mSendCmd = sendCmd;
    }

    //{"cmd":"query","data":"000000C0","functionCode":1,"result":"success"}
    public String getData() {
        String data = null;
        try {
            JSONObject jsonObject = new JSONObject(mJsonResult);
            if (jsonObject.has("data")) {
                data = jsonObject.getString("data");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (data == null) {
            data = "";
        }
        return data;
    }

    ///获取c++层面解析的错误消息
    public String getExceptionMessage() {
        String exception = null;
        try {
            JSONObject object = new JSONObject(mJsonResult);
            if (object.has("cmd") && object.has("description")) {
                String cmd = object.getString("cmd");
                if (cmd.equals("exception")) {
                    exception = object.getString("description");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return exception;
    }

    ///是否是c++异常消息
    public boolean isExceptionMessage() {
        return !TextUtils.isEmpty(getExceptionMessage());
    }

    @Override
    public String toString() {
        return "MachineRespond{" +
                "mHexResult='" + mHexResult + '\'' +
                ", mJsonResult='" + mJsonResult + '\'' +
                ", mParserResult='" + mParserResult + '\'' +
                ", mSendCmd='" + mSendCmd + '\'' +
                '}';
    }

    //MachineRespond{mHexResult='FE0100140004000000F024BC', mJsonResult='{"cmd":"query","data":"000000F0","functionCode":1,"result":"success"}', mParserResult='正常待机', mSendCmd='', mParserResultNumArr='00XXXX,normal'}
}
